package com.shine.demo.jvm.tuning;

import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class OOMTest {
    public static List<Object> list = new ArrayList<>();
    public static final String CODE_ERR = "-99999";

    // ‐Xms10M ‐Xmx10M ‐XX:+PrintGCDetails ‐XX:+HeapDumpOnOutOfMemoryError ‐XX:HeapDumpPath=D:\jvm.dump
    public static void main(String[] args) {
        List<Object> list = new ArrayList<>();
        int i = 0;
        int j = 0;
        while (true) {
            list.add(new User(i++, UUID.randomUUID().toString()));
            new User(j--, UUID.randomUUID().toString());
        }
//        System.out.println(test());
    }

    public static String test(){
        try{
            int a = 10/0;
            return a+"";
        }catch (Exception e){
            return CODE_ERR;
        }finally {
            return "最终执行";
        }
    }

    public static void test2(){
        //软引用
        SoftReference<String> user = new SoftReference<String>("缓存数据");
        //弱引用
        WeakReference<String> user2 = new WeakReference<String>("弱引用对象");
    }

}
